package com.ruoyi.ucar.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.obs.services.model.AccessControlList;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.ucar.boreq.*;
import com.ruoyi.ucar.boresp.*;
import com.ruoyi.ucar.common.CommonCheXinMengBoResp;
import com.ruoyi.ucar.common.CommonVoResp;
import com.ruoyi.ucar.common.ResultEnum;
import com.ruoyi.ucar.domain.TOrder;
import com.ruoyi.ucar.service.ISysFileMainService;
import com.ruoyi.ucar.service.ITOrderService;
import com.ruoyi.ucar.service.UCarQueryApiService;
import com.ruoyi.ucar.util.CommonUtil;
import com.ruoyi.ucar.util.PuppeteerScreenshotUtil;
import com.ruoyi.ucar.util.ResponseUtil;
import com.ruoyi.ucar.voreq.*;
import com.ruoyi.ucar.voresp.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 订单主Controller
 * 
 * @author sungangbin
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/ucar/order")
@Api(value = "订单管理",tags = "订单管理模块接口")
public class TOrderController extends BaseController
{
    @Autowired
    private ITOrderService tOrderService;

    @Autowired
    private UCarQueryApiService uCarQueryApiService;



    /**
     * 订单上传临时签名图片
     */
    @ApiOperation("订单上传临时签名图片接口-mobile使用")
    @PostMapping(value = "/uploadOrderSign")
    public CommonVoResp<OrderSignVoResq> uploadOrderSign(UploadOrderSignVoReq uploadOrderSignVoReq)
    {
        CommonVoResp<OrderSignVoResq> commonVoResp=new CommonVoResp<>();
        if(StringUtils.isNull(uploadOrderSignVoReq.getFile())){
            return CommonUtil.setCommonVoRespNoSignParam(commonVoResp);
        }
        OrderSignQueryBoReq orderSignQueryBoReq=new OrderSignQueryBoReq();
        orderSignQueryBoReq.setOrderCode(uploadOrderSignVoReq.getOrderCode());
        OrderSignBoResq orderSignBoResq=tOrderService.judgeOrderSign(orderSignQueryBoReq);
        if(StringUtils.isNull(orderSignBoResq)){
            commonVoResp.setCode(ResultEnum.ORDERNODATA.getCode());
            commonVoResp.setMessage(ResultEnum.ORDERNODATA.getMsg());
            logger.info("订单上传临时签名图片接口-mobile使用出参:{}",commonVoResp);
            return commonVoResp;
        }else{
//            if (!orderSignBoResq.getSignFlag()) {
                try {
                    String   signFileMainUuid= tOrderService.uploadOrderSign(CommonUtil.objToObj(uploadOrderSignVoReq,UploadOrderSignBoReq.class));
                    OrderSignVoResq orderSignVoResq=new OrderSignVoResq();
                    orderSignVoResq.setSignFlag(new Boolean(true));
                    orderSignVoResq.setSignFileMainUuid(signFileMainUuid);
                    commonVoResp.setData(orderSignVoResq);
                } catch (IOException e) {
                    commonVoResp.setCode(ResultEnum.ORDERSIGNFAIL.getCode());
                    commonVoResp.setMessage(ResultEnum.ORDERSIGNFAIL.getMsg());
                }
//            }else{
//                OrderSignVoResq orderSignVoResq=CommonUtil.objToObj(orderSignBoResq,OrderSignVoResq.class);
//                commonVoResp.setData(orderSignVoResq);
//            }
        }
        logger.info("订单上传临时签名图片接口-mobile使用出参：{}",commonVoResp);
        return commonVoResp;
    }

    /**
     * 新增订单
     */
    @ApiOperation("新增订单-mobile使用")
    @PostMapping("/addOrder")
    public CommonVoResp<UcarOrderVoResp> add(@RequestBody  UcarOrderVoReq ucarOrderVoReq)
    {

        logger.info("新增订单VO端入参:{}",ucarOrderVoReq);
        CommonVoResp<UcarOrderVoResp> commonVoResp=new CommonVoResp<>();

        if(
                StringUtils.isEmpty(ucarOrderVoReq.getVinNo())||
                StringUtils.isNull(ucarOrderVoReq.getProductUuidList())||ucarOrderVoReq.getProductUuidList().size()==0
        ){
            commonVoResp = CommonUtil.setCommonVoRespNoParam(commonVoResp);
            return commonVoResp;
        }
        UcarOrderBoReq ucarOrderBoReq= CommonUtil.objToObj(ucarOrderVoReq, UcarOrderBoReq.class);
        logger.info("新增订单VO端转BO端入参:{}",ucarOrderBoReq);
        UcarOrderBoResp ucarOrderBoResp= null;
        try {
            ucarOrderBoResp = tOrderService.initOrder(ucarOrderBoReq);
//            if(StringUtils.isNull(ucarOrderBoResp.getOrderUuid())){
//                commonVoResp.setCode(ResultEnum.BRANDNOCARQUERY.getCode());
//                commonVoResp.setMessage(ResultEnum.BRANDNOCARQUERY.getMsg());
//                return commonVoResp;
//            }
        } catch (IOException e) {
            commonVoResp = CommonUtil.setCommonVoRespNoDataError(commonVoResp);
            return commonVoResp;
        }
        logger.info("新增订单BO端出参:{}",ucarOrderBoResp);
        UcarOrderVoResp ucarOrderVoResp=CommonUtil.objToObj(ucarOrderBoResp,UcarOrderVoResp.class);
        logger.info("新增订单BO端转VO端出参:{}",ucarOrderVoResp);
        commonVoResp.setData(ucarOrderVoResp);
        return commonVoResp;
    }

    @ApiOperation("修改订单状态-mobile使用")
    @PostMapping("/updateOrderStatus")
    public CommonVoResp<String> updateOrderStatus(@RequestBody UcarOrderUpdateStatusVoReq ucarOrderUpdateStatusVoReq)
    {
        CommonVoResp<String> commonVoResp=new CommonVoResp<>();
        if(StringUtils.isEmpty(ucarOrderUpdateStatusVoReq.getOrderUuid())||(
                StringUtils.isEmpty(ucarOrderUpdateStatusVoReq.getOrderStatus())&&
                        StringUtils.isEmpty(ucarOrderUpdateStatusVoReq.getPayStatus())
                )){
            commonVoResp = CommonUtil.setCommonVoRespNoParam(commonVoResp);
            return commonVoResp;
        }
        logger.info("修改订单状态VO端入参:{}",ucarOrderUpdateStatusVoReq);
        UcarOrderUpdateStatusBoReq ucarOrderUpdateStatusBoReq= CommonUtil.objToObj(ucarOrderUpdateStatusVoReq,  UcarOrderUpdateStatusBoReq.class);
        logger.info("修改订单状态VO端转BO端入参:{}",ucarOrderUpdateStatusBoReq);
        int updateNumber= tOrderService.updateOrderStatus(ucarOrderUpdateStatusBoReq,null);
        commonVoResp.setData((updateNumber>0 ? "订单状态修改成功":"订单状态修改失败"));
        logger.info("修改订单状态出参:{}",commonVoResp);
        return  commonVoResp;
    }

    @ApiOperation("用户的未读报告数量减一接口")
    @PostMapping("/reportUnReadMinusOne")
    public CommonVoResp<String> reportUnReadMinusOne(@RequestBody ReportUnReadMinusOneVoReq reportUnReadMinusOneVoReq)
    {
        CommonVoResp<String> commonVoResp=new CommonVoResp<>();
        if(StringUtils.isEmpty(reportUnReadMinusOneVoReq.getOrderUuid())
        ){
            commonVoResp = CommonUtil.setCommonVoRespNoParam(commonVoResp);
            return commonVoResp;
        }
        logger.info("用户的未读报告数量减一VO端入参:{}",reportUnReadMinusOneVoReq);
        ReportUnReadMinusOneBoReq reportUnReadMinusOneBoReq= CommonUtil.objToObj(reportUnReadMinusOneVoReq,  ReportUnReadMinusOneBoReq.class);
        logger.info("用户的未读报告数量减一VO端转BO端入参:{}",reportUnReadMinusOneBoReq);
        int updateNumber= tOrderService.reportUnReadMinusOne(reportUnReadMinusOneBoReq);
        commonVoResp.setData((updateNumber>0 ? "用户的未读报告数量减一修改成功":"用户的未读报告数量减一修改失败"));
        logger.info("用户的未读报告数量减一出参:{}",commonVoResp);
        return  commonVoResp;
    }


    @ApiOperation("订单支付成功后调用车辆查询接口-仅限柠檬查或车信盟-mobile使用")
    @PostMapping("/orderUseUcarQueryApi")
    public CommonVoResp<List<UcarOrderQueryApiVoResq>>  orderUseUcarQueryApi(@RequestBody UcarOrderQueryApiVoReq ucarOrdeQueryApiVoReq){
        CommonVoResp<List<UcarOrderQueryApiVoResq>> commonVoResp=new CommonVoResp<>();
        logger.info("订单支付成功后调用车辆查询接口入参:{}",ucarOrdeQueryApiVoReq);
        Wrapper<TOrder> wrapper=new LambdaQueryWrapper<TOrder>().eq(TOrder::getOrderUuid,ucarOrdeQueryApiVoReq.getOrderUuid()).eq(TOrder::getDeleteFlag,1l);
        List<TOrder>  tOrderList=tOrderService.list(wrapper);
        if(tOrderList==null||tOrderList.size()==0){
            commonVoResp = CommonUtil.setCommonVoRespNoDataError(commonVoResp);
            return commonVoResp;
        }else{
            if(!"paid".equals(tOrderList.get(0).getPayStatus())){
                commonVoResp = CommonUtil.setCommonVoRespCarQueryNoPayError(commonVoResp);
                return commonVoResp;
            }

        }
        List<UcarOrderQueryApiBoResq>  ucarOrdeQueryApiBoResqList= tOrderService.orderUseUcarQueryApi(CommonUtil.objToObj(ucarOrdeQueryApiVoReq, UcarOrderQueryApiBoReq.class),tOrderList.get(0));
        List<UcarOrderQueryApiVoResq>  ucarOrdeQueryApiVoResqList=new ArrayList<>();
        for (UcarOrderQueryApiBoResq ucarOrdeQueryApiBoResq:
        ucarOrdeQueryApiBoResqList) {
            UcarOrderQueryApiVoResq ucarOrdeQueryApiVoResq=CommonUtil.objToObj(ucarOrdeQueryApiBoResq, UcarOrderQueryApiVoResq.class);
            ucarOrdeQueryApiVoResqList.add(ucarOrdeQueryApiVoResq);
        }
        commonVoResp.setData(ucarOrdeQueryApiVoResqList);
        logger.info("订单支付成功后调用车辆查询接口出参:{}",commonVoResp);
        return  commonVoResp;
    };

    @ApiOperation("订单支付成功后手动上传查询报告接口")
    @PostMapping("/orderCommitReport")
    public CommonVoResp<UcarOrderCommitReportVoResq>  orderCommitReport(UcarOrderCommitReportVoReq ucarOrderCommitReportVoReq){
        CommonVoResp<UcarOrderCommitReportVoResq> commonVoResp=new CommonVoResp<>();
        logger.info("订单支付成功后手动上传查询报告接口:{}",ucarOrderCommitReportVoReq);
        Wrapper<TOrder> wrapper=new LambdaQueryWrapper<TOrder>().eq(TOrder::getOrderUuid,ucarOrderCommitReportVoReq.getOrderUuid()).eq(TOrder::getDeleteFlag,1l);
        List<TOrder>  tOrderList=tOrderService.list(wrapper);
        if(StringUtils.isEmpty(ucarOrderCommitReportVoReq.getOrderUuid())||StringUtils.isEmpty(ucarOrderCommitReportVoReq.getOrderProductDataUuid())||(StringUtils.isNull(ucarOrderCommitReportVoReq.getFiles())||ucarOrderCommitReportVoReq.getFiles().size()==0)
        ){
            commonVoResp = CommonUtil.setCommonVoRespNoParam(commonVoResp);
            return commonVoResp;
        }
        if(tOrderList==null||tOrderList.size()==0){
            commonVoResp = CommonUtil.setCommonVoRespNoDataError(commonVoResp);
            return commonVoResp;
        }else{
            if(!"paid".equals(tOrderList.get(0).getPayStatus())){
                commonVoResp = CommonUtil.setCommonVoRespCarCommitNoPayError(commonVoResp);
                return commonVoResp;
            }
        }
        //todo
        UcarOrderCommitReportBoReq ucarOrderCommitReportBoReq=CommonUtil.objToObj(ucarOrderCommitReportVoReq,UcarOrderCommitReportBoReq.class);
        UcarOrderCommitReportBoResq ucarOrderCommitReportBoResq= tOrderService.orderCommitReport(ucarOrderCommitReportBoReq,tOrderList.get(0));
        UcarOrderCommitReportVoResq ucarOrderCommitReportVoResq=CommonUtil.objToObj(ucarOrderCommitReportBoResq,UcarOrderCommitReportVoResq.class);
        commonVoResp.setData(ucarOrderCommitReportVoResq);
        logger.info("订单支付成功后手动上传查询报告接口:{}",commonVoResp);
        return  commonVoResp;
    };


    /**
     * 查询订单主列表
     */
    @ApiOperation("代理商订单列表查询-mobile使用")
    @PostMapping("/proxyMobileList")
    public CommonVoResp<OrderQueryProxyListVoResp>  proxyMobileList(@RequestBody OrderListProxyQueryVoReq orderListProxyQueryVoReq)
    {
        logger.info("代理商订单列表-mobile使用接口入参:{}",orderListProxyQueryVoReq);
        CommonVoResp<OrderQueryProxyListVoResp> commonVoResp=new CommonVoResp<>();
        OrderListProxyQueryBoReq orderListProxyQueryBoReq=CommonUtil.objToObj(orderListProxyQueryVoReq, OrderListProxyQueryBoReq.class);
        OrderQueryProxyListBoResp orderQueryProxyListBoResp= tOrderService.proxyQueryOrderByCond(orderListProxyQueryBoReq);
        if(StringUtils.isNotNull(orderQueryProxyListBoResp)){
            OrderQueryProxyListVoResp orderQueryProxyListVoResp=new OrderQueryProxyListVoResp();
            List<OrderQueryProxyListVo> orderQueryProxyListVos=new ArrayList<>();
            orderQueryProxyListBoResp.getOrderQueryProxyListBos().forEach(orderQueryProxyListBo -> {
                OrderQueryProxyListVo orderQueryProxyListVo=CommonUtil.objToObj(orderQueryProxyListBo,OrderQueryProxyListVo.class);
                orderQueryProxyListVos.add(orderQueryProxyListVo);
            });
            orderQueryProxyListVoResp.setOrderQueryProxyListVos(orderQueryProxyListVos);
            commonVoResp.setData(orderQueryProxyListVoResp);
        }else{
            return CommonUtil.setCommonVoRespNoDataError(commonVoResp);
        }
        logger.info("订单列表查询-mobile使用接口出参:{}",commonVoResp);
        return commonVoResp;
    }
    @Autowired
    private ISysFileMainService sysFileMainService;
    /**
     *报告转图片-测试接口
     */
    @ApiOperation("报告转图片-测试接口")
    @PostMapping("/screenShot")
    @Anonymous
    public  CommonVoResp<String>  screenShot(@RequestBody TestVoReq testVoReq)
    {

        CommonVoResp<String> commonVoResp=new CommonVoResp<>();
        FileInputStream fileInputStream=null;
        File file=null;
        try {
            String fileName=CommonUtil.createUuid()+".png";
            String filePath="/aiit/imageTempPath/"+fileName;
            PuppeteerScreenshotUtil.captureFullPage(
                    testVoReq.getUrl(),filePath,"9500"
            );
            file=new File(filePath);
            fileInputStream=new FileInputStream(file);
            String fileURl = sysFileMainService.obsUploadFile(fileName,fileInputStream, AccessControlList.REST_CANNED_PUBLIC_READ);
            commonVoResp.setData(fileURl);
            return commonVoResp;
         } catch (Exception e) {
         }finally {
            if(StringUtils.isNotNull(fileInputStream))
            {
                try {
                    fileInputStream.close();
                } catch (IOException e) {
                 }
            }

        }
        return null;
    }



    /**
     * 查询订单主列表
     */
    @ApiOperation("订单列表查询-mobile使用")
    @PostMapping("/mobileList")
    public CommonVoResp<OrderMobileQueryListVoResp>  mobileList(@RequestBody OrderMobileQueryListVoReq orderMobileQueryListVoReq)
    {
        logger.info("订单列表查询-mobile使用接口入参:{}",orderMobileQueryListVoReq);
        CommonVoResp<OrderMobileQueryListVoResp> commonVoResp=new CommonVoResp<>();
        OrderMobileQueryListBoReq orderMobileQueryListBoReq=CommonUtil.objToObj(orderMobileQueryListVoReq, OrderMobileQueryListBoReq.class);
        OrderMobileQueryListBoResp orderMobileQueryListBoResp= tOrderService.mobileQueryOrderByCond(orderMobileQueryListBoReq);
        if(StringUtils.isNotNull(orderMobileQueryListBoResp)){
            OrderMobileQueryListVoResp orderMobileQueryListVoResp=new OrderMobileQueryListVoResp();
            List<OrderMobileQueryListVo> orderMobileQueryListVos=new ArrayList<>();
            orderMobileQueryListBoResp.getOrderMobileQueryListBos().forEach(orderMobileQueryListBo -> {
                OrderMobileQueryListVo orderMobileQueryListVo=CommonUtil.objToObj(orderMobileQueryListBo,OrderMobileQueryListVo.class);
                orderMobileQueryListVos.add(orderMobileQueryListVo);
            });
            orderMobileQueryListVoResp.setOrderMobileQueryListVos(orderMobileQueryListVos);
            commonVoResp.setData(orderMobileQueryListVoResp);
        }else{
            return CommonUtil.setCommonVoRespNoDataError(commonVoResp);
        }
        logger.info("订单列表查询-mobile使用接口出参:{}",commonVoResp);
        return commonVoResp;
    }

    @ApiOperation("订单的报告html查询-mobile使用")
    @PostMapping("/getReportHtml")
    public CommonVoResp<OrderReportHtmlVoResp>  getReportHtml(@RequestBody  OrderReportHtmlVoReq orderReportHtmlVoReq){

        logger.info("订单的报告html查询入参:{}",orderReportHtmlVoReq);
        CommonVoResp<OrderReportHtmlVoResp> commonVoResp=new CommonVoResp<>();
        if(StringUtils.isEmpty(orderReportHtmlVoReq.getOrderUuid())){
            commonVoResp = CommonUtil.setCommonVoRespNoParam(commonVoResp);
            return commonVoResp;
        }
        OrderDetailQueryBoReq orderDetailQueryBoReq=new OrderDetailQueryBoReq();
        orderDetailQueryBoReq.setOrderUuid(orderReportHtmlVoReq.getOrderUuid());
        OrderDetailQueryBoResp orderDetailQueryBoResp=tOrderService.orderDetailQuery2(orderDetailQueryBoReq);
        if(StringUtils.isNull(orderDetailQueryBoResp)){
            commonVoResp = CommonUtil.setCommonVoRespNoDataError(commonVoResp);
        }else {
            if(StringUtils.isEmpty(orderDetailQueryBoResp.getQueryreportUrl())){
                 commonVoResp.setCode(ResultEnum.ORDERNOREPORT.getCode());
                 commonVoResp.setMessage(ResultEnum.ORDERNOREPORT.getMsg());
            }else{
                String html=null;
                OrderReportHtmlVoResp orderReportHtmlVoResp=new OrderReportHtmlVoResp();
                if(StringUtils.isNotEmpty(orderDetailQueryBoResp.getQueryreportUrl())){
                      html=HttpUtil.get(orderDetailQueryBoResp.getQueryreportUrl());
                }else{
                    CheXinMengGetReportBoReq cheXinMengGetReportBoReq=new CheXinMengGetReportBoReq();
                    cheXinMengGetReportBoReq.setOrderId(orderDetailQueryBoResp.getQueryreportOrderId());
                    CommonCheXinMengBoResp commonCheXinMengBoResp= uCarQueryApiService.cheXinMengGetReport(cheXinMengGetReportBoReq);
                    if(StringUtils.isNotNull(commonCheXinMengBoResp.getReturnObj())){
                        html=HttpUtil.get(((CheXinMengGetReportBoResp)commonCheXinMengBoResp.getReturnObj()).getReportUrl());
                    }
                }

//                html=html.replace("https://oapi.lemonstea.com/lemon-report/static/accident_css_mobile/index250225.css","https://ucar.mycrab.cn/prod-api/css/index250225.css");
//                html=html.replace("https://oapi.lemonstea.com/lemon-report/static/common_js/jquery-1.10.1.js","https://ucar.mycrab.cn/prod-api/js/jquery-1.10.1.js");
                orderReportHtmlVoResp.setReportHtml(html);
                commonVoResp.setData(orderReportHtmlVoResp);
            }
        }
        logger.info("订单的报告html查询出参:{}",commonVoResp);
        return commonVoResp;
    }


    /**
     * 查询订单主列表
     */
    @ApiOperation("订单列表查询-web使用")
    @PostMapping("/list")
    public CommonVoResp<OrderQueryListVoResp> list(@RequestBody OrderListQueryVoReq orderListQueryVoReq)
    {
        CommonVoResp<OrderQueryListVoResp> commonVoResp=new CommonVoResp<>();
        logger.info("订单列表查询VO端入口参数:{}",orderListQueryVoReq);
        if(
                orderListQueryVoReq.getPageIndex()==null||
                        orderListQueryVoReq.getPageSize()==null){
            return CommonUtil.setCommonVoRespNoParam(commonVoResp);
        }
        OrderListQueryBoReq orderListQueryBoReq=CommonUtil.objToObj(orderListQueryVoReq,OrderListQueryBoReq.class);
        orderListQueryBoReq.setPageIndex(orderListQueryVoReq.getPageIndex());
        orderListQueryBoReq.setPageSize(orderListQueryVoReq.getPageSize());
        OrderQueryListBoResp  orderQueryListBoResp=tOrderService.queryOrderListByCond(orderListQueryBoReq);
        if(StringUtils.isNotNull(orderQueryListBoResp)){
            OrderQueryListVoResp orderQueryListVoResp=new OrderQueryListVoResp();
            List<OrderQueryListVo> orderQueryListVos=new ArrayList<>();
            orderQueryListVoResp.setTotalCount(orderQueryListBoResp.getTotalCount());
            orderQueryListVoResp.setTotalPage(orderQueryListBoResp.getTotalPage());
            orderQueryListBoResp.getOrderQueryListBos().forEach(orderQueryListBo -> {
                OrderQueryListVo orderQueryListVo=CommonUtil.objToObj(orderQueryListBo,OrderQueryListVo.class);
                if( StringUtils.isNotNull(orderQueryListBo.getQueryreportUrls())&&orderQueryListBo.getQueryreportUrls().size()>0){
                    List<String> queryreportUrls=new ArrayList<>();
                    orderQueryListBo.getQueryreportUrls().forEach(queryReportUrl->{
                        queryreportUrls.add(queryReportUrl);
                    });
                    orderQueryListVo.setQueryreportUrls(queryreportUrls);
                }
                orderQueryListVos.add(orderQueryListVo);
            });
            orderQueryListVoResp.setOrderQueryListVos(orderQueryListVos);
            commonVoResp.setData(orderQueryListVoResp);
        }else{
            return CommonUtil.setCommonVoRespNoDataError(commonVoResp);
        }
        logger.info("订单列表查询出参：{}",commonVoResp);
        return commonVoResp;
    }


    /**
     * 查询订单主列表
     */
    @ApiOperation("车信盟报告url查询")
    @PostMapping("/cheXinMenUrlList")
    @Anonymous
    public CommonVoResp<CheXinMengUrlListVoResp> cheXinMenUrlList(@RequestBody CheXinMengUrlListQueryVoReq cheXinMengUrlListQueryVoReq)
    {
        CommonVoResp<CheXinMengUrlListVoResp> commonVoResp=new CommonVoResp<>();
        logger.info("车信盟报告url查询入口参数:{}",cheXinMengUrlListQueryVoReq);
         if(
                 cheXinMengUrlListQueryVoReq.getOrderUuid()==null){
            return CommonUtil.setCommonVoRespNoParam(commonVoResp);
        }
        CheXinMengUrlListQueryBoReq cheXinMengUrlListQueryBoReq=CommonUtil.objToObj(cheXinMengUrlListQueryVoReq,CheXinMengUrlListQueryBoReq.class);
        CheXinMengUrlListBoResp cheXinMengUrlListBoResp=tOrderService.cheXinMenUrlList(cheXinMengUrlListQueryBoReq);
        if(StringUtils.isNotNull(cheXinMengUrlListBoResp)&&StringUtils.isNotNull(cheXinMengUrlListBoResp.getReportUrls())&&cheXinMengUrlListBoResp.getReportUrls().size()>0){
            CheXinMengUrlListVoResp cheXinMengUrlListVoResp=new CheXinMengUrlListVoResp();
            List<String> reportUrls=new ArrayList<>();
            cheXinMengUrlListBoResp.getReportUrls().forEach(reportUrl->{
                reportUrls.add(reportUrl);
            });
            cheXinMengUrlListVoResp.setReportUrls(reportUrls);
            commonVoResp.setData(cheXinMengUrlListVoResp);
        }
        logger.info("车信盟报告url查询查询出参：{}",commonVoResp);
        return commonVoResp;
    }

    /**
     * 导出订单主列表
     */
    @PreAuthorize("@ss.hasPermi('ucar:order:export')")
    @Log(title = "订单主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TOrder tOrder)
    {
        List<TOrder> list = tOrderService.selectTOrderList(tOrder);
        ExcelUtil<TOrder> util = new ExcelUtil<TOrder>(TOrder.class);
        util.exportExcel(response, list, "订单主数据");
    }

    /**
     * 获取订单主详细信息
     */
    @ApiOperation("获取订单详细信息接口-orderUuid或id，两者传一即可")
    @PostMapping(value = "/detail")
    public CommonVoResp<OrderDetailQueryVoResp> detail(@RequestBody OrderDetailQueryVoReq orderDetailQueryVoReq)
    {
        CommonVoResp<OrderDetailQueryVoResp> commonVoResp=new CommonVoResp<>();
        logger.info("获取订单详细信息入参：{}",orderDetailQueryVoReq);
        if(
                orderDetailQueryVoReq.getOrderUuid()==null&&
                        orderDetailQueryVoReq.getId()==null){
            return CommonUtil.setCommonVoRespNoParam(commonVoResp);
        }
        OrderDetailQueryBoResp orderDetailQueryBoResp=tOrderService.orderDetailQuery(CommonUtil.objToObj(orderDetailQueryVoReq, OrderDetailQueryBoReq.class));

        if(StringUtils.isNull(orderDetailQueryBoResp)){
            return CommonUtil.setCommonVoRespNoDataError(commonVoResp);
        }else{
            OrderDetailQueryVoResp orderDetailQueryVoResp=CommonUtil.objToObj(orderDetailQueryBoResp,OrderDetailQueryVoResp.class);
            if( StringUtils.isNotNull(orderDetailQueryBoResp.getQueryreportUrls())&&orderDetailQueryBoResp.getQueryreportUrls().size()>0){
                List<String> queryreportUrls=new ArrayList<>();
                orderDetailQueryBoResp.getQueryreportUrls().forEach(queryReportUrl->{
                    queryreportUrls.add(queryReportUrl);
                });
                orderDetailQueryVoResp.setQueryreportUrls(queryreportUrls);
            }
            commonVoResp.setData(orderDetailQueryVoResp);
        }
        logger.info("获取订单详细信息出参：{}",commonVoResp);
        return commonVoResp;
    }



    /**
     * 修改订单主
     */
    @PreAuthorize("@ss.hasPermi('ucar:order:edit')")
    @Log(title = "订单主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TOrder tOrder)
    {
        return toAjax(tOrderService.updateTOrder(tOrder));
    }

    /**
     * 删除订单主
     */
    @ApiOperation("删除订单接口-id和orderUuid，两者传一即可")
    @PostMapping("/delete")
    public CommonVoResp<String> delete(@RequestBody DeleteOrderVoReq deleteOrderVoReq)
    {
        CommonVoResp<String> commonVoResp=new CommonVoResp<>();
        if(
                deleteOrderVoReq.getOrderUuid()==null&&
                        deleteOrderVoReq.getId()==null){
            return CommonUtil.setCommonVoRespNoParam(commonVoResp);
        }
        logger.info("删除订单入参：{}",deleteOrderVoReq);
        return ResponseUtil.commonDeleteResult(tOrderService.deleteTOrderById(deleteOrderVoReq.getOrderUuid(),deleteOrderVoReq.getId()),commonVoResp);
    }


    @ApiOperation("领取返现金额-mobile使用")
    @PostMapping("/getReturnMoney")
    public CommonVoResp<OrderGetReturnMoneyVoResp>  getReturnMoney(@RequestBody  OrderGetReturnMoneyVoReq orderGetReturnMoneyVoReq){

        logger.info("领取返现金额查询入参:{}",orderGetReturnMoneyVoReq);
        CommonVoResp<OrderGetReturnMoneyVoResp> commonVoResp=new CommonVoResp<>();
        if(StringUtils.isEmpty(orderGetReturnMoneyVoReq.getOrderUuid())){
            commonVoResp = CommonUtil.setCommonVoRespNoParam(commonVoResp);
            return commonVoResp;
        }
        OrderGetReturnMoneyBoResp orderGetReturnMoneyBoResp=tOrderService.getReturnMoney(CommonUtil.objToObj(orderGetReturnMoneyVoReq,OrderGetReturnMoneyVoReq.class));
        commonVoResp.setData(CommonUtil.objToObj(orderGetReturnMoneyBoResp,OrderGetReturnMoneyVoResp.class));
        logger.info("领取返现金额查询出参:{}",commonVoResp);
        return commonVoResp;
    }
}
